/*
 * Copyright (C) 2014 Francisco José Morero Peyrona. All Rights Reserved.
 *
 * This file is part of JStatViewer project: https://code.google.com/p/jstat-viewer/
 *
 * GNU Classpath is free software; you can redistribute it and/or modify it
 * under the terms of the GNU General Public License as published by the free
 * Software Foundation; either version 3, or (at your option) any later version.
 *
 * Tapas is distributed in the hope that it will be useful, but WITHOUT ANY
 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
 * A PARTICULAR PURPOSE.  See the GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License along with
 * Tapas; see the file COPYING.  If not, write to the Free Software Foundation,
 * Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
 */

package jstatviewer;

import javax.swing.JOptionPane;
import javax.swing.UIManager;
import javax.swing.UnsupportedLookAndFeelException;

/**
 * Some useful static functions.
 *
 * @author peyrona
 */
public class Util
{
    public static boolean isEmpty( String s )
    {
        return (s == null || s.trim().isEmpty());
    }

    public static boolean isNotEmpty( String s )
    {
        return ! isEmpty( s );
    }

    public static void showInfo( String msg )
    {
        JOptionPane.showMessageDialog( Main.getFrame(), msg, "Message", JOptionPane.INFORMATION_MESSAGE );
    }

    public static void showError( String msg )
    {
        JOptionPane.showMessageDialog( Main.getFrame(), msg, "Error", JOptionPane.ERROR_MESSAGE );
    }

    public static void setLookAndFeel()
    {
        try
        {
            String sClassName = null;

            for( UIManager.LookAndFeelInfo info : UIManager.getInstalledLookAndFeels() )
            {
                if( "Nimbus".equals( info.getName() ) )    // TODO: leer el L&F de las properties
                {
                    sClassName = info.getClassName();
                    break;
                }
            }

            UIManager.setLookAndFeel( sClassName );
        }
        catch( ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException exc )
        {
            try
            {
                UIManager.setLookAndFeel( UIManager.getCrossPlatformLookAndFeelClassName() );
            }
            catch( ClassNotFoundException | InstantiationException | IllegalAccessException | UnsupportedLookAndFeelException e )
            {
                System.out.println( "Error iniciando L&F. Esto no debería ocurrir." );
            }
        }
    }

    //----------------------------------------------------------------------------//

    /**
     * To avoid instantiating this class.
     */
    private Util()
    {
    }
}